package com.dycx.user.converter;

import java.time.LocalDateTime;

import cn.hutool.core.bean.BeanUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.user.entity.VehicleBrandDO;
import com.dycx.user.vo.VehicleBrandVO;
import com.dycx.user.dto.VehicleBrandDTO;

/**
 * 车辆表(VehicleBrand)实体转换类
 *
 * @author wuzongbing
 * @since 2025-01-19 18:06:08
 */


@Data
public class VehicleBrandConverter implements Serializable {
    public static VehicleBrandDO dtoToEntity(VehicleBrandDTO dto) {
        if (dto == null) return null;
        VehicleBrandDO entity = BeanUtil.toBean(dto, VehicleBrandDO.class);
        return entity;
    }

    public static VehicleBrandVO entityToVo(VehicleBrandDO entity) {
        if (entity == null) return null;
        VehicleBrandVO vo = BeanUtil.toBean(entity, VehicleBrandVO.class);

        return vo;
    }

    public static List<VehicleBrandVO> entityToVoList(List<VehicleBrandDO> entityList) {
        List<VehicleBrandVO> voList = new ArrayList<>();
        for (VehicleBrandDO entity : entityList) {
            voList.add(entityToVo(entity));
        }
        return voList;
    }

    public static Page<VehicleBrandVO> entityToVoPage(Page<VehicleBrandDO> page) {

        List<VehicleBrandVO> newRecords = new ArrayList<>();

        List<VehicleBrandDO> records = page.getRecords();
        for (VehicleBrandDO entity : records) {
            newRecords.add(entityToVo(entity));
        }

        Page<VehicleBrandVO> voPage = new Page<>();
        voPage.setRecords(newRecords);
        voPage.setPages(page.getPages());
        voPage.setTotal(page.getTotal());
        voPage.setSize(page.getSize());
        voPage.setCurrent(page.getCurrent());

        return voPage;
    }

}
